<?php
declare(strict_types=1);

namespace App\Controller\Backend;

use App\Logic\AdminRedbillLogic;
use Exception;
use Hyperf\HttpServer\Annotation\AutoController;
use Psr\Http\Message\ResponseInterface;

#[AutoController(prefix: '/redbill', server: 'backend')]
class RedbillController extends AbstractController
{
    /**
     * 方案列表
     * @return ResponseInterface
     */
    public function lists(): ResponseInterface
    {
        $input = $this->request->all();
        return $this->apiReturn(200, 'succ', AdminRedbillLogic::listProject($input));
    }

    /**
     * 方案详情
     * @return ResponseInterface
     */
    public function detail(): ResponseInterface
    {
        $projectId = $this->request->input('projectId', '');
        if (empty($projectId)) {
            return $this->apiReturn(400, '参数错误');
        }
        try {
            $detail = AdminRedbillLogic::detailProject($projectId);
            return $this->apiReturn(200, 'succ', $detail);
        } catch (Exception $e) {
            return $this->apiReturn(400, $e->getMessage());
        }
    }

    /**
     * 方案订单
     * @return ResponseInterface
     */
    public function orderList(): ResponseInterface
    {
        $projectId = $this->request->input('projectId', '');
        if (empty($projectId)) {
            return $this->apiReturn(400, '参数错误');
        }
        $input = $this->request->all();
        try {
            return $this->apiReturn(200, 'succ', AdminRedbillLogic::orderProject($projectId, $input));
        } catch (Exception $e) {
            return $this->apiReturn(400, $e->getMessage());
        }
    }
}